using Vben.Admin.Launch;
using Vben.Common.Core;
using Vben.Common.Sqlsugar;
using Vben.Common.Sqlsugar.Config;

var builder = WebApplication.CreateBuilder(args);

builder.Configuration.AddJsonFile("Properties/Configs/web.json", optional: true, reloadOnChange: true);
if (builder.Environment.IsDevelopment())
{
    builder.Configuration.AddJsonFile("Properties/Configs/web.Development.json", optional: true, reloadOnChange: true);
}
else if (builder.Environment.IsProduction())
{
    builder.Configuration.AddJsonFile("Properties/Configs/web.Production.json", optional: true, reloadOnChange: true);
}
builder.Configuration.AddJsonFile("Properties/Configs/Cache.json");

//配置文件
builder.Services.AddSingleton(new AppSettings(builder.Configuration));
// builder.Services.Configure<OptionsSetting>(builder.Configuration);

builder.Services.AddDb();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();

// 配置 Swagger 生成器
builder.Services.AddSwaggerGen();

builder.Services.AddSwaggerConfig();


var app = builder.Build();
MyApp.Configuration = builder.Configuration;
MyApp.ServiceProvider = app.Services;
MyApp.WebHostEnvironment = app.Environment;

app.DbFirst();
app.MapControllers(); 

// 启用swagger时需要将 vben.common.core引入vben.common.furion
app.UseSwagger();

// 启用 Swagger UI 中间件（提供 Web 界面）
// app.UseSwaggerUI(c =>
// {
//     c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
// });

app.Run();


